#ifndef TIMEOUT_MANAGER
#define TIMEOUT_MANAGER

#include <csignal>
#include <ctime>
#include <map>
#include <set>


// Signal sent when timer expired
const int TIMEOUT_SIG = SIGALRM;


/*
 * Class for handling timeouts
 */	
class TimeoutManager
{
	public:		
		~TimeoutManager();	
		/*
		 * Launches timer for waiting client
		 * pid			- pid of the waiting client
		 * miliseconds  - timeout in miliseconds
		 *
		 * returns 		- true if timer launch was succesful
		 */			
		bool launchTimer(pid_t pid, int miliseconds);
		
		/*
		 * Informs timeout manager that timeout of the timer connected with 
		 * client process was handled, and timer resources can be released
		 */			
		void timeoutHandled(pid_t pid);
		
	private:
		typedef std::map<pid_t, timer_t> TimersMap;
		
		TimersMap timers_;
};

#endif
